﻿@using System.Data;
@{
    ViewBag.Title = "编辑类别";
    int channel_id = ViewBag.channel_id;
    DTcms.Model.site_channel channelModel = ViewBag.channelModel;
    DataTable CategorySpec = ViewBag.CategorySpec;
}
@model DTcms.Model.article_category
@section HeaderContent{
    <script type="text/javascript" charset="utf-8" src="/scripts/ueditor/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="/scripts/ueditor/ueditor.all.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="/scripts/ueditor/lang/zh-cn/zh-cn.js"></script>
}
<form id="form1" class="layui-form" novalidate="novalidate" url="CategorySave?action=@ViewBag.action&id=@ViewBag.id&channel_id=@channel_id">
    @Html.AntiForgeryToken()
    <!--导航栏-->
    <div class="pageheader">
        <div class="page-bar">
            <ul class="page-breadcrumb">
                <li><a href="../article/category_list?channel_id=@channel_id" class="back"><i class="fa fa-mail-reply-all"></i> 返回列表页</a></li>
                <li><a href="javascript:;"><i class="iconfont icon-home1"></i> 首页</a> </li>
                <li><a href="../article/category_list?channel_id=@channel_id">内容类别</a> </li>
                <li><a href="javascript:;">编辑分类</a> </li>
            </ul>
        </div>
    </div>
    <!--/导航栏-->
    <!--内容-->
    <div class="layui-fluid">
        <div class="layui-tab layui-tab-card">
            <ul class="layui-tab-title" id="floatHead">
                <li class="layui-this">基本信息</li>
                <li>扩展选项</li>
            </ul>
            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">
                    <div class="layui-form-item">
                        <label class="layui-form-label">所属父类别</label>
                        <div class="layui-input-block">
                            <select class="select" name="parent_id" url="/webapi/categoryJson?id=@channel_id" selectValue="@Model.parent_id" promtion="无父级类别"><option value="">无父级类别</option></select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">排序数字</label>
                        <div class="layui-input-block">
                            @Html.TextBox("sort_id", Model.sort_id, new { @class = "input small", datatype = "n", sucmsg = " " })
                            <span class="Validform_checktip">*数字，越小越向前</span>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">类别名称</label>
                        <div class="layui-input-block">@Html.TextBox("title", Model.title, new { @class = "input normal", datatype = "*1-100", sucmsg = " " }) <span class="Validform_checktip">*类别中文名称，100字符内</span></div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">调用别名</label>
                        <div class="layui-input-block">
                            @Html.TextBox("call_index", Model.call_index, new { @class = "input normal", datatype = @"/^\s*$|^[a-zA-Z0-9\-\_]{2,50}$/", errormsg = "请填写正确的别名", sucmsg = " " })
                            <span class="Validform_checktip">类别的调用别名，只允许字母、数字、下划线</span>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">状态</label>
                        <div class="layui-input-block">
                            @Html.RadioButton("is_lock", "0", Model.is_lock == 0, new { title = "显示" })
                            @Html.RadioButton("is_lock", "1", Model.is_lock == 1, new { title = "锁定" })
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">SEO标题</label>
                        <div class="layui-input-block">
                            @Html.TextArea("seo_title", Model.seo_title, new { @class = "input normal", maxlength = "255", datatype = "*0-100", sucmsg = " " })
                            <span class="Validform_checktip">255个字符以内</span>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">SEO关健字</label>
                        <div class="layui-input-block">
                            @Html.TextArea("seo_keywords", Model.seo_keywords, new { @class = "input" })
                            <span class="Validform_checktip">以“,”逗号区分开，255个字符以内</span>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">SEO描述</label>
                        <div class="layui-input-block">
                            @Html.TextArea("seo_description", Model.seo_description, new { @class = "input" })
                            <span class="Validform_checktip">255个字符以内</span>
                        </div>
                    </div>
                </div>
                <div class="layui-tab-item">
                    <div class="layui-form-item">
                        <label class="layui-form-label">优先显示内容</label>
                        <div class="layui-input-block">
                            @Html.RadioButton("is_page", 0, Model.is_page == 0, new { title = "否" })
                            @Html.RadioButton("is_page", 1, Model.is_page == 1, new { title = "是" })
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">文字颜色</label>
                        <div class="layui-inline">
                            @Html.TextBox("color", Model.color, new { @class = "input normal short", style = "" + (Model.color == "" ? "" : "color:" + Model.color) + "" })
                        </div>
                        <div class="layui-inline" style="left: -16px;top:3px"><div id="btnColor"></div></div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">URL链接</label>
                        <div class="layui-input-block">
                            @Html.TextBox("link_url", Model.link_url, new { @class = "input normal", maxlength = "255" })
                            <span class="Validform_checktip">填写后直接跳转到该网址</span>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">显示图片</label>
                        <div class="layui-input-block">
                            @Html.TextBox("img_url", Model.img_url, new { @class = "input normal upload-path" })
                            <div class="upload-box choose-pick"><a href="javascript:;" class="webuploader-pick" title="图片空间">选择图片</a></div>
                            <div class="upload-box upload-img"></div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">类别介绍</label>
                        <div class="layui-input-block">
                            @Html.TextArea("content", Model.content, new { @style = "height:300px; width:100%;" })
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!--/内容-->
    <!--工具栏-->
    <div class="page-footer">
        <div class="btn-wrap">
            <button class="layui-btn icon-btn" id="btnSubmit"><i class="layui-icon layui-icon-ok"></i>提交保存</button>
            <button class="layui-btn layui-btn-warm icon-btn" name="btnReturn" onclick="javascript:history.back(-1);"><i class="layui-icon layui-icon-return"></i>返回上一页</button>
        </div>
    </div>
    <!--/工具栏-->
</form>
@section Scripts{
    <script type="text/javascript" src="/scripts/libs/js/uploader.js"></script>
    <script type="text/javascript">
        layui.use(['validform', 'element', 'colorpicker', 'jqueryform', 'cascadeSelect', 'laydate', 'fileChoose'], function () {
            var colorpicker = layui.colorpicker, cascadeSelect = layui.cascadeSelect, fileChoose = layui.fileChoose, laydate = layui.laydate;
            cascadeSelect.init('parent_id', false);
            laydate.render({
                elem: '#add_time'
                ,type: 'datetime'
            });
            $('.choose-pick').click(function () {
                var obj = $(this);
                fileChoose.open({
                    fileUrl: '',
                    listUrl: '/admin_ajax/files',
                    num: 1,
                    dialog: {
                        offset: '60px'
                    },
                    onChoose: function (res) {
                        if (res[0].type != "file") {
                            layer.msg('我只让你选择图片格式的文件', { icon: 2, time: 2000 }, function () { });
                            return;
                        }
                        obj.siblings(".upload-path").val(res[0].url);
                        obj.siblings(".layer-photos").show().find("img").attr("src", res[0].url);
                    }
                });
            });
            //初始化表单验证
            $("#form1").initValidform('#btnSubmit', 1);
            //初始化上传控件
            $(".upload-img").InitUploader({ sendurl: "/upload_ajax/action", swf: "/scripts/libs/module/uploader/uploader.swf" });
            //初始化ueditor
            var ue = UE.getEditor('content');

            colorpicker.render({
                elem: '#btnColor'
                , color: '@Model.color'
                , predefine: true // 开启预定义颜色
                , done: function (color) {
                    $("#color").val(color).css("color", color);
                }
            });
            //绑定品牌按钮
            $("#brandAddButton").click(function () {
                var liObj = $(this).parent();
                var d = layer.open({
                    type: 2,
                    area: ['500px', '300px'],
                    title: "品牌关联",
                    maxmin: true,
                    content: '../dialog/dialog_category_brand?channel_id=@ViewBag.channel_id',
                    btn: ["确定", '关闭'],
                    btn1: function (index, layero) {
                        var iframeWin = window[layero.find('iframe')[0]['name']];
                        iframeWin.execSpecHtml(obj);
                    },
                    success: function (layero, index) {
                        var body = layer.getChildFrame('body', index);
                        var iframeWin = window[layero.find('iframe')[0]['name']];
                        iframeWin.submitValue(liObj);
                    },
                    cancel: function (index, layero) { }
                });
            });
            //绑定规格按钮
            $("#specAddButton").click(function () {
                var liObj = $(this).parent();
                var d = layer.open({
                    type: 2,
                    area: ['600px', '400px'],
                    title: "规格关联",
                    maxmin: true,
                    content: '../dialog/dialog_category_spec?channel_id=@ViewBag.channel_id',
                    btn: ["确定", '关闭'],
                    btn1: function (index, layero) {
                        var iframeWin = window[layero.find('iframe')[0]['name']];
                        iframeWin.appendSpecHtml(liObj);
                        layer.close(index);
                    },
                    success: function (layero, index) {
                        var body = layer.getChildFrame('body', index);
                        var iframeWin = window[layero.find('iframe')[0]['name']];
                        //将容器对象传进去
                        iframeWin.submitValue(liObj);
                    },
                    cancel: function (index, layero) { }
                });
            });
            //绑定扩展字段按钮
            $("#fieldAddButton").click(function () {
                var liObj = $(this).parent();
                var d = layer.open({
                    type: 2,
                    area: ['600px', '400px'],
                    title: "扩展字段关联",
                    maxmin: true,
                    content: '../dialog/dialog_category_attribute?channel_id=@ViewBag.channel_id',
                    btn: ["确定", '关闭'],
                    btn1: function (index, layero) {
                        var iframeWin = window[layero.find('iframe')[0]['name']];
                        iframeWin.appendSpecHtml(liObj);
                        layer.close(index);
                    },
                    success: function (layero, index) {
                        var body = layer.getChildFrame('body', index);
                        var iframeWin = window[layero.find('iframe')[0]['name']];
                        //将容器对象传进去
                        iframeWin.submitValue(liObj);
                    },
                    cancel: function (index, layero) { }
                });
            });
            //删除附件节点
            window.delNode= function(obj) {
                $(obj).parent().remove();
            }
        });
    </script>
}